use syscall::data::EventStruct;

pub mod fs;
pub mod utils;

pub fn do_event(request_fd: usize) {
    let mut request_buf = alloc::vec![0u8; size_of::<EventStruct>()];
    syscall::op::read(request_fd, &mut request_buf);

    let request = &unsafe { *(request_buf.as_ptr() as *const EventStruct) };
    if request.magic != 0x20091103 {
        return;
    }
    let ret = match request.cmd {
        1 => self::fs::fs_read(request),
        2 => self::fs::fs_write(request),
        3 => self::fs::fs_fsize(request),
        4 => self::fs::fs_list(request),
        _ => 0,
    };

    let buf = alloc::vec![
        0xFFu8,
        (ret >> 56) as u8,
        (ret >> 48) as u8,
        (ret >> 40) as u8,
        (ret >> 32) as u8,
        (ret >> 24) as u8,
        (ret >> 16) as u8,
        (ret >> 8) as u8,
        ret as u8,
    ];

    syscall::op::write(request_fd, &buf);
}
